use cmsis_rtos2_rs::{os_delay, static_mem::{Task, Thread}};

use crate::app::{self, proto::{self, Cmd}, service::dispatcher::send_to_ipc};




static THREAD: Thread<1024> = Thread::uninit();

struct StatusTask;

impl Task for StatusTask {

    fn run(&self) {
        let mut seq = 0;

        #[cfg(feature = "cp_drop")]
        const STATUS: u8 = proto::cmd::drop::STATUS;

        #[cfg(feature = "cp_cargo")]
        const STATUS: u8 = proto::cmd::cargo::STATUS;

        loop {
            #[cfg(feature = "cp_drop")]
            let status = app::drop::status::collect();

            #[cfg(feature = "cp_cargo")]
            let status = app::cargo::status::collect();
            
            send_to_ipc(&Cmd::new_notify(seq, STATUS, status));
            seq = seq.wrapping_add(1);

            os_delay(500);
        }
    
    }
}

pub unsafe fn start() {
    THREAD.spawn(&StatusTask);
}




